package com.mlk.rbac.controller;

import java.util.List;

import javax.annotation.Resource;

import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.rbac.Service.SysDictService;
import com.mlk.rbac.Service.SysDictTypeService;
import com.mlk.rbac.dto.SysDictDTO;
import com.mlk.rbac.po.SysDict;
import com.mlk.rbac.po.SysDictType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 系统数据字典
 * @author trekxu
 *
 */
@Controller
@RequestMapping("/rbac/dict")
public class SysDictController {
	
	/**
	 * 返回到数据字典首页
	 * @return
	 */
	@RequestMapping("index")
	public String index() {
		return "rbac/dict";
	}
	
	@Resource
	private SysDictService sysDictService;
	
	@Resource
	private SysDictTypeService sysDictTypeService;
	
	/**
	 * 数据字典类型分页列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/type/pageList")
	public Pager<SysDictType> dictTypePageList(Integer type,SysDictType dictType){
		return this.sysDictTypeService.dictTypePageList(type,dictType);
	} 
	
	/**
	 * 数据字典类型列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/type/list")
	public List<SysDictType> dictTypeList(Integer type){
		return this.sysDictTypeService.dictTypeList(type);
	} 
	
	/**
	 * 数据字典类型添加
	 * @param dictType
	 * @return
	 */
	@RequestMapping("/type/add")
	@ResponseBody
	public ServerResponse dictTypeAdd(SysDictType dictType) {
		return this.sysDictTypeService.dictTypeAdd(dictType);
	}
	
	/**
	 * 开启或者冻结字典类型
	 * @param id
	 * @return
	 */
	@RequestMapping("/type/onOrOff")
	@ResponseBody
	public ServerResponse dictTypeOnOrOff(Integer id) {
		return this.sysDictTypeService.dictTypeOnOrOff(id);
	}
	
	/**
	 * 更新数据字典
	 * @param typeName
	 * @return
	 */
	@RequestMapping("/type/update")
	@ResponseBody
	public ServerResponse dictTypeUpdate(Integer id ,String typeName) {
		return this.sysDictTypeService.dictTypeUpdate(id,typeName);
	}
	
	/**
	 * 获取字典列表
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public Pager<SysDictDTO> dictList(String dictType){
		return this.sysDictService.dictList(dictType);
	}
	
	/**
	 * 通过id删除字典
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public ServerResponse dictDelete(Integer id) {
		return this.sysDictService.dictDelete(id);
	}
	
	/**
	 * 更新字典内容
	 * @param dict
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/update")
	public ServerResponse dictUpdate(SysDictDTO dict) {
		return this.sysDictService.dictUpdate(dict);
	}
	
	/**
	 * 新增字典
	 * @param dict
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/add")
	public ServerResponse dictAdd(SysDict dict) {
		return this.sysDictService.dictAdd(dict);
	}

    /**
     * 加载系统的字典内容
     * @param typeDesc
     * @return
     */
	@RequestMapping("findDictTypeByDesc")
    @ResponseBody
	public ServerResponse findDictTypeByDesc(String typeDesc){
	    return this.sysDictTypeService.findDictTypeByDesc(typeDesc);
    }
}	
